Skip to content

Call back a delayed send and restore a trashed entry - #312

Merged
jeremy merged 5 commits into
mainfrom
undo-send-restore-entry
Nov 20, 2026
Merged

jeremy merged 5 commits into
mainfrom
undo-send-restore-entry

Conversation

@jeremy

@jeremy jeremy commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

HEY's Undo Send and its restore-from-Trash for a single entry were the two routes a caller needed to take back a send or a deleted draft, and both sat in spec/excluded-routes.json. This models them, so the hosted HEY MCP server can offer "undo that send" and "bring that draft back" without driving the paths by hand.

What it adds

  • UndoTopicSend: POST /topics/{topicId}/undo_send.json. Calls back the last message the caller sent on a topic while Undo Send still holds it. The message is a draft again, unsent.
  • RestoreEntry: PUT /entries/{entryId}/status/active.json. Takes one entry out of the Trash. Idempotent: an entry that isn't in the Trash is left as it is.

Both leave excluded-routes.json for route-coverage.json, and every generated client gains the two operations.

HEY answers both with a 303 and no body, and for the undo that redirect's Location is the only place HEY names the entry it called back (/messages/{id}/edit for a message on its own thread, /topics/{topicId}?expanded_draft={id} for a reply). HEY picks the entry, the caller's last delayed one on the topic, so it need not be the one the caller meant. The hand-written layer therefore takes the redirect as the answer rather than follow it:

Undo, answering the entry Reading an entry out of a Location
Go Topics().UndoSend(ctx, topicID) (entryID int64, err error) UndoneEntryID(location) (int64, bool)
Rust Topics::undo_topic_send(topic_id) -> Result<Option<i64>, Error> services::undone_entry_id(&str) -> Option<i64>
Kotlin TopicsService.undoTopicSend(topicId): Long? undoneEntryId(String): Long?
Swift TopicsService.undoTopicSend(topicId:) -> Int? undoneEntryId(_:) -> Int?

Go also gains Entries().Restore(ctx, entryID) error, which takes its redirect the same way, so a failed read of the thread can't report a restore that went through as one that didn't, and Client.PutForm, which completes the form family beside PostForm and DeleteForm.

Too late is told from undone. With nothing left to call back (the delay ran out and the message went, or none was held) HEY answers 400 and changes nothing. Every SDK surfaces that as an API error whose HTTP status is 400. A success is a nil error and, from the conveniences, the entry.

The undo is never resent. A second undo would call back the next delayed entry on the thread, so UndoTopicSend is one attempt, whatever the client's retry settings. RestoreEntry is idempotent and retries a 429 or 503 once.

SentMessage.undo_action's comment said HEY offers a scoped token no Undo Send. It does now, to a token holding write approved since HEY widened that scope, and the comment says so.

How it was checked against HEY

Read from haystack's master, and exercised there with controller tests against a local build (not against production):

  • Topics::UndoSendsController#create undoes topic.last_delayed_entry_for(user:) and redirects to the draft, or answers 400 when there is none. Entry::Delayable holds a send for 15 seconds and offers the undo for 12.
  • Entries::StatusController#active restores the entry alone. A draft that was its topic's only entry took the topic to the Trash with it, and restoring just the entry leaves a draft on a trashed topic. RestoreTopic is the call for that one, and the operation's comment says which to use when.
  • Scopes: both take write (approved since the widening). Restoring a draft that is scheduled to send needs send as well, since a draft keeps its schedule in the Trash.

Nothing in haystack changes for this, and no existing caller of either route sees a difference.

TypeScript

The TypeScript client follows no redirect and reports any non-2xx as an error, so there a successful undoTopicSend or restoreEntry throws a HeyError whose httpStatus is 303, with no Location. That is documented on the two methods and in typescript/README.md, and held by typescript/tests/client.test.ts, rather than changed here: making a redirect an answer in TypeScript is a transport change that deserves its own PR (a model-level "the redirect is the answer" trait would also let the other generated clients stop following). Four conformance cases that need a followed or captured redirect are marked not applicable for TypeScript for the same reason.

Tests

  • Go, Rust, Kotlin and Swift unit tests: both Location shapes, a bare /topics/{id} not read as an undo, non-positive ids refused, the 400, one request after a 503.
  • Go: only a 302 or a 303 is the answer to an undo or a restore. A 301, 307 or 308 is not followed and is an error with its status, as in the other SDKs' redirect capture.
  • Conformance: two path cases, and six behaviour cases in conformance/tests/undo-restore.json (the entry out of each Location shape, the 400, no resend of an undo after a 503 from either layer, one resend of a restore). Go, Rust, Kotlin and Swift run 237 of 237; TypeScript runs 228 with 9 not applicable.
  • make check passes on the head.
  • Mutation check on the conveniences: 24 of 24 caught (eight in each of Rust, Kotlin and Swift: redirect followed, either Location shape unread, non-positive ids accepted, a bare topic read as an undo, the 400 swallowed or unworded, a resend after 503).

Additive. No release, tag or version bump here.

Model HEY's Undo Send for a topic (POST /topics/{topicId}/undo_send) and
an entry's restore from the trash (PUT /entries/{entryId}/status/active),
both of which HEY answers with a 303 rather than a body.

Go's Topics().UndoSend takes the redirect as the answer and reads the
entry HEY called back out of its Location, since HEY undoes the caller's
last delayed entry on the topic, which need not be the one meant. A 400
is too late: nothing was held. Entries().Restore takes its redirect the
same way, so a failed read of the thread can't report a restore that went
through as one that didn't. PutForm completes the form family for a
caller driving the path itself.
Rust's Topics::undo_topic_send and Kotlin's and Swift's undoTopicSend send
UndoTopicSend from its generated route without following HEY's 303, and
answer the entry its Location names: Go's Topics().UndoSend, ported. HEY
undoes the caller's last delayed entry on the topic, which need not be the
one meant, and the Location is the only place it says which.

A 400 is reworded inside the operation as Go words it, nothing to undo,
with HEY's status and request id kept, so the hooks hear the error the
caller gets. undone_entry_id and undoneEntryId read the entry out of a
Location for a caller holding one, against Go's table of what is and is
not an undo's redirect.

The generated undo_send and undoSend still follow the redirect. PARITY.md
gains the rows for the undo and for the entry restore, which Rust leaves
to the generated method.

Kotlin's and Swift's route counts move to 141 for the two operations the
last commit modelled.
The path cases for UndoTopicSend and RestoreEntry answer what HEY answers,
a 303 and then the read a generated client follows it to. undo-restore.json
holds the behaviour. The hand-written Undo Send takes the redirect for its
answer in one request and reads the entry out of either Location shape. A
400 is an error with that status, asked once. A 503 is not answered with a
resend, by the convenience or the generated operation, under a client that
allows three. RestoreEntry is resent once and stops at its two attempts.

Each runner dispatches UndoTopicSend and RestoreEntry to the generated
operation and UndoSend to its convenience, answering {"entry_id"} for
responseBody to read. Go's HEY layer sends RestoreEntry through
Entries().Restore.

TypeScript follows no redirect, so the four cases a 303 succeeds in are
not applicable there: its client reports the 303 as an error with that
status, which its README now says of these two writes. Its own tests hold
that, the single send of an undo and the resend of a restore, and its
runner sends the undo's error cases through the generated operation.
The spec said a generated client follows the 303 UndoTopicSend and
RestoreEntry answer with. TypeScript's follows none: there a HeyError whose
httpStatus is 303 is the write having gone through, and it carries no
Location, so it cannot say which entry an undo called back. The comment is
printed on TypeScript's own methods, so it says so there.

Every generated tree is regenerated for the comment.
Copilot AI balanced review requested due to automatic review settings November 19, 2026 23:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical issues can falsely report successful writes without delivering mutations and misclassify a delivery-capable restore operation as mailbox-only for downstream policy consumers.

2 open issues
What changed in this PR

Adds modeled Undo Send and single-entry restore operations across the five HEY SDKs, enabling callers such as the hosted MCP server to use generated APIs rather than construct paths manually.

Changes:

  • Models both routes and generates client methods, route metadata, and coverage records.
  • Adds undo conveniences that capture the redirect and return the recalled entry ID, plus Go restore and PutForm support.
  • Adds redirect, error, and retry tests; documents TypeScript’s existing treatment of successful redirects as errors.

[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

File Description
typescript/​tests/​client.test.ts Tests redirect errors and retry limits.
typescript/​src/​generated/​schema.ts Adds operation types and updates scope documentation.
typescript/​src/​generated/​operations.ts Adds methods and retry metadata.
typescript/​src/​generated/​coverage.json Registers both operations.
typescript/​README.md Documents redirect behavior and conformance exclusions.
swift/​Tests/​HeyTests/​TopicsTests.swift Tests undo results, errors, and Location parsing.
swift/​Tests/​HeyTests/​RouteTests.swift Updates the expected route count.
swift/​Sources/​Hey/​Services/​TopicsService+Conveniences.swift Adds redirect-capturing undo and entry-ID parsing.
swift/​Sources/​Hey/​Generated/​Services/​TopicsService.swift Adds generated undo method.
swift/​Sources/​Hey/​Generated/​Services/​EntriesService.swift Adds generated restore method.
swift/​Sources/​Hey/​Generated/​Routes.swift Adds routes and retry policies.
swift/​Sources/​Hey/​Generated/​Models/​SentMessage.swift Corrects undo-action scope documentation.
spec/​route-coverage.json Records both modeled routes.
spec/​hey.smithy Defines operations, behavior traits, and documentation.
spec/​excluded-routes.json Removes the newly modeled routes.
rust/​hey-sdk/​tests/​services_topics.rs Tests undo behavior and Location parsing.
rust/​hey-sdk/​src/​services/​topics.rs Adds redirect-capturing undo and entry-ID parsing.
rust/​hey-sdk/​src/​services/​mod.rs Exports the parser and updates convenience documentation.
rust/​hey-sdk/​src/​generated/​types.rs Corrects undo-action scope documentation.
rust/​hey-sdk/​src/​generated/​services/​topics.rs Adds generated undo method.
rust/​hey-sdk/​src/​generated/​services/​entries.rs Adds generated restore method.
rust/​hey-sdk/​src/​generated/​routes.rs Adds routes and retry policies.
rust/​hey-sdk/​PARITY.md Documents Go/Rust undo and restore differences.
openapi.json Adds generated operation contracts and metadata.
kotlin/​sdk/​src/​commonTest/​kotlin/​com/​basecamp/​hey/​TopicsServiceTest.kt Tests undo behavior and Location parsing.
kotlin/​sdk/​src/​commonTest/​kotlin/​com/​basecamp/​hey/​RouteTest.kt Updates the expected route count.
kotlin/​sdk/​src/​commonMain/​kotlin/​com/​basecamp/​hey/​services/​TopicsService.kt Adds redirect-capturing undo and entry-ID parsing.
kotlin/​sdk/​src/​commonMain/​kotlin/​com/​basecamp/​hey/​generated/​services/​TopicsService.kt Adds generated undo method.
kotlin/​sdk/​src/​commonMain/​kotlin/​com/​basecamp/​hey/​generated/​services/​EntriesService.kt Adds generated restore method.
kotlin/​sdk/​src/​commonMain/​kotlin/​com/​basecamp/​hey/​generated/​Routes.kt Adds routes and retry policies.
kotlin/​sdk/​src/​commonMain/​kotlin/​com/​basecamp/​hey/​generated/​models/​SentMessage.kt Corrects undo-action scope documentation.
go/​pkg/​hey/​url-routes.json Registers both URL patterns.
go/​pkg/​hey/​undo_restore_test.go Tests undo, restore, parsing, and PUT forms.
go/​pkg/​hey/​topics.go Adds undo wrapper and entry-ID parser.
go/​pkg/​hey/​entries.go Adds redirect-capturing restore wrapper.
go/​pkg/​hey/​client.go Adds redirect capture support and PutForm.
go/​pkg/​generated/​client.gen.go Generates operations, response parsers, and metadata.
conformance/​tests/​undo-restore.json Adds shared undo and restore behavior cases.
conformance/​tests/​paths.json Adds route and redirect-following cases.
conformance/​runner/​typescript/​runner.ts Maps the undo alias and updates exclusion count.
conformance/​runner/​typescript/​README.md Updates coverage totals and redirect limitations.
conformance/​runner/​typescript/​not-applicable.json Excludes four unsupported redirect cases.
conformance/​runner/​typescript/​fixture-inventory.json Registers the new conformance cases.
conformance/​runner/​swift/​Sources/​ConformanceRunner/​Operations.swift Dispatches new operations and undo convenience.
conformance/​runner/​rust/​src/​operations.rs Dispatches new operations and undo convenience.
conformance/​runner/​kotlin/​src/​main/​kotlin/​com/​basecamp/​hey/​conformance/​Operations.kt Dispatches new operations and undo convenience.
conformance/​runner/​go/​main.go Dispatches generated operations and Go wrappers.
behavior-model.json Adds operation effects and retry policies.

Review effort: Balanced

Comment thread go/pkg/hey/client.go Resolved
Comment thread spec/hey.smithy Resolved
Go's Topics().UndoSend and Entries().Restore took any 3xx as the write
having gone through. A 307 or 308 asks for the write to be sent again
somewhere else, and a 301 is no answer to a write either: the hop is not
taken, so the write reached nowhere and was reported as done. For an undo
that is a message said to be called back that goes out.

Only a 302 or a 303 is the answer now, as Go's form transport and the
Rust, Kotlin and Swift redirect capture already have it. Any other
redirect is still not followed, and is an API error with its status.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approved

No active review issues remain for the Undo Send and single-entry restore additions.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@jeremy

jeremy commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Review summary for head 4c7f19e.

State. Every check has finished on 4c7f19e: 35 pass, and the one neutral is cubic, which reviewed nothing here because the team's monthly line limit is used up (it resumes 1 December). Copilot reviewed 7a2cda2 with two findings and approved 4c7f19e. Both threads are resolved, and the branch merges cleanly into main.

Fixed (1 of 2). Go took any 3xx as a completed write. redirectAnswer takes only a 302 or a 303 now, as the form transport and the Rust, Kotlin and Swift redirect capture already did. A 301, 307 or 308 is not followed and is an API error with its status. TestRedirectAsAnswerTakesOnlyACompletedWritesRedirect holds it for the undo and the restore, and fails on the old check.

Declined (1 of 2). Mark RestoreEntry open-world. HEY does flush an entry Undo Send still holds before changing its status, but that message was already sent and goes out within the hold regardless: the restore starts no delivery and gives content no new way out, which is what heyOpenWorld marks. MarkEntrySpam (same controller, same flush), RestoreTopic and TrashTopic are modelled heyOpenWorld(false) on the same reading, so this operation matches them. Changing the reading is a change to the four together and its own PR. The reasoning is in the thread.

Left as documented, for a person to decide. TypeScript's client follows no redirect and reports a non-2xx as an error, so a successful undoTopicSend or restoreEntry there throws a HeyError with httpStatus 303 and no Location. The methods' comments, typescript/README.md and typescript/tests/client.test.ts say and hold that. Making a redirect an answer in TypeScript is a transport change, not made here.

No release, tag or version bump is part of this. Not merged: that is a person's call.

@jeremy
jeremy merged commit 61aade2 into main Nov 20, 2026
36 checks passed
@jeremy
jeremy deleted the undo-send-restore-entry branch November 20, 2026 00:14
@jeremy jeremy mentioned this pull request Nov 20, 2026
jeremy added a commit that referenced this pull request Nov 20, 2026
Release bump for 0.36.0 (make bump VERSION=0.36.0): chrono replaced by jiff in Rust (#311), and UndoTopicSend and RestoreEntry (#312).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants